#include <stdio.h>
int addition(int i,int j)
{
	return i + j;
}
int substraction(int i,int j)
{
	return i - j;
}
int multiplication(int i,int j)
{
	return i * j;
}
int division(int i,int j)
{
	return i / j;
}
void menu(void)
{
	printf("**************************\n");
	printf("**  0 => addition       **\n");
	printf("**  1 => substraction   **\n");
	printf("**  2 => multiplication **\n");
	printf("**  3 => division       **\n");
	printf("**  4 => quit           **\n");
}
int main(void)
{
	int (*actions[])(int,int) = {addition,substraction,multiplication,division};
	int action = 0,max_action_index = sizeof(actions) / sizeof(actions[0]) - 1,left,right,result;
	while(1)
	{
		menu();
		printf("Enter your action:");
		scanf("%d",&action);
		setbuf(stdin,NULL);
		if(action == 4)
		{
			printf("Bye\n");
			break;
		}
		if(action > 0 || action < max_action_index)
		{
			printf("Enter your variables:");
			scanf("%d %d",&left,&right);
			result = actions[action](left,right);
			printf("result is %d\n",result);
		}
		else
		{
			printf("Bad action!\n");
		}
		int c;
		while((c = getchar()) != '\n' && c != EOF);		
		action = max_action_index;
		setbuf(stdin,NULL);
	}	
}
